﻿using gerecord;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace gemysql
{
    public class UpStream : IUpStream<long, CombiEntity>
    {
        public void Dispose()
        {
            
        }

        public async Task<CombiEntity> LoadAsync(long key)
        {
            using(var db = new EntityContext())
            {
                return new CombiEntity();
            }
        }

        public async Task SaveAsync(Dictionary<long, CombiEntity> entities)
        {
            using(var db = new EntityContext())
            {
                int i = 0;
                foreach(var et in entities)
                {
                    //添加entity
                    i++;
                    if(i >= 1000)
                    {
                        await db.SaveChangesAsync();
                        i = 0;
                    }
                }
                await db.SaveChangesAsync();

            }
        }

        public async Task<CombiEntity> UpdateAsync(CombiEntity ov, CombiEntity nv)
        {
            //纯内存操作
            return nv;
        }
    }
}
